package org.example;

import java.util.ArrayList;

//从一行输入的文字中，生成键值对，写入到context
public class Mapper {
    public void map(String line,Context context){
        if(line.substring(0,1).matches("[0-9]{1}"))
        {
            boolean flag = false;
            if(line.contains("_"))
            {
                line = line.replace("_","");
                flag = true;
            }
            //对输入文件进行处理
            String[] values = line.split("\t");
            String t = values[0];
            String[] vals = values[1].split(" ");
            String url="_";//保存url，用作下次计算
            double pr = 0;
            int i = 0;
            int num = 0;



            i=1;
            pr=Double.valueOf(vals[0]);
            num=vals.length-1;

            for(;i<vals.length;i++)
            {
                url=url+vals[i]+" ";
                String prt = String.valueOf(pr/num);
                context.write(vals[i],prt);
            }
            context.write(t,url);
        }
    }
}
